<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$Title$</title>

    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/zTreeStyle/zTreeStyle.css" type="text/css">

    <script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery.ztree.core.js"></script>
</head>
<body class="fixed-sidebar full-height-layout">
<div class="zTreeDemoBackground left">
    <ul id="treeDemo" class="ztree"></ul>
</div>
<div style="text-align: right;float:right;" >
    <button type="button" class="btn btn-primary" id="enter" >确定</button>
    <button type="button" class="btn btn-default" id="cancel">取消</button>
</div>
</body>





<script>

    var setting = {
        async: {
            enable: true,
            url:"${request.contextPath}/menuManage/showTree",
            autoParam:["id", "name=n", "level=lv"],
            otherParam:{"otherParam":"zTreeAsyncTest"},
            dataFilter: filter
        },
        view: {
            showIcon: true
        },

        callback:{
            onClick:zTreeOnClick
        }
    };

    function filter(treeId, parentNode, childNodes) {
        if (!childNodes) return null;

        return childNodes;
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting);
    });

    var _id = null;
    var _name = null;
    function zTreeOnClick(event, treeId, treeNode, clickFlag) {
        _id = treeNode.id;
        _name = treeNode.name;
        console.log(_id);
        console.log(_name);
    }

    $("#enter").on('click',function () {
        var index = parent.layer.getFrameIndex(window.name);
        if(_id && _name){
            parent.$("#parentId").val(_id);
            parent.$("#menuName").val(_name);
        }
        parent.layer.close(index);//关闭当前页

    });

    $("#cancel").on('click',function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    });
</script>
</html>
